package com.ddone.gmall.mock;

import com.ddone.gmall.mock.service.*;
import com.ddone.util.mock.ParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ddone
 * @date 2024/5/26-18:55
 */
@Component
@Slf4j
public class MockTask {

    @Resource
    private CartInfoService cartInfoService;

    @Resource
    private UserInfoService userInfoService;

    @Resource
    private FavorInfoService favorInfoService;

    @Resource
    private OrderInfoService orderInfoService;

    @Resource
    private OrderRefundInfoService orderRefundInfoService;

    @Resource
    private PaymentInfoService paymentInfoService;

    @Resource
    private CommentInfoService commentInfoService;

    @Value("${mock.clear:0}")
    String ifClear;

    @Value("${mock.user.clear:0}")
    String ifClearUser;


    @Transactional(rollbackFor = Exception.class)
    public void mainTask( ) {
        log.warn("--------开始生成数据--------");
        Boolean ifClear = ParamUtil.checkBoolean(this.ifClear);

        log.warn("--------开始生成用户数据--------");
        userInfoService.genUserInfos( ParamUtil.checkBoolean(this.ifClearUser));

        log.warn("--------开始生成收藏数据--------");
        favorInfoService.genFavors( ifClear);

        log.warn("--------开始生成购物车数据--------");
        cartInfoService.genCartInfo(ifClear);

        log.warn("--------开始生成订单数据--------");
        orderInfoService.genOrderInfos( ifClear);

        log.warn("--------开始生成支付数据--------");
        paymentInfoService.genPayments(ifClear);

        log.warn("--------开始生成退单数据--------");
        orderRefundInfoService.genRefundsOrFinish(ifClear);

        log.warn("--------开始生成评价数据--------");
        commentInfoService.genComments( ifClear);
    }
}
